package com.springboot.cms.blogroll.controller;


import com.springboot.cms.blogroll.domain.CmsBlogroll;
import com.springboot.cms.blogroll.service.ICmsBlogrollService;
import com.springboot.common.annotation.Log;
import com.springboot.common.core.controller.BaseController;
import com.springboot.common.core.domain.AjaxResult;
import com.springboot.common.core.page.TableDataInfo;
import com.springboot.common.enums.BusinessType;
import com.springboot.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 友情链接Controller
 *
 * @author lhxz
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/cms/blogroll")
public class CmsBlogrollController extends BaseController
{
    @Autowired
    private ICmsBlogrollService cmsBlogrollService;

    /**
     * 查询友情链接列表
     */
//    @PreAuthorize("@ss.hasPermi('cms:blogroll:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsBlogroll cmsBlogroll)
    {
        startPage();
        List<CmsBlogroll> list = cmsBlogrollService.selectCmsBlogrollList(cmsBlogroll);
        return getDataTable(list);
    }

    /**
     * 导出友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('cms:blogroll:export')")
    @Log(title = "友情链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsBlogroll cmsBlogroll)
    {
        List<CmsBlogroll> list = cmsBlogrollService.selectCmsBlogrollList(cmsBlogroll);
        ExcelUtil<CmsBlogroll> util = new ExcelUtil<CmsBlogroll>(CmsBlogroll.class);
        util.exportExcel(response, list, "友情链接数据");
    }

    /**
     * 获取友情链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:blogroll:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsBlogrollService.selectCmsBlogrollById(id));
    }

    /**
     * 新增友情链接
     */
    @PreAuthorize("@ss.hasPermi('cms:blogroll:add')")
    @Log(title = "友情链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsBlogroll cmsBlogroll)
    {
        return toAjax(cmsBlogrollService.insertCmsBlogroll(cmsBlogroll));
    }

    /**
     * 修改友情链接
     */
    @PreAuthorize("@ss.hasPermi('cms:blogroll:edit')")
    @Log(title = "友情链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsBlogroll cmsBlogroll)
    {
        return toAjax(cmsBlogrollService.updateCmsBlogroll(cmsBlogroll));
    }

    /**
     * 删除友情链接
     */
    @PreAuthorize("@ss.hasPermi('cms:blogroll:remove')")
    @Log(title = "友情链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsBlogrollService.deleteCmsBlogrollByIds(ids));
    }
}
